package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsFriendlyLink;
import com.ruoyi.system.domain.news.query.NewsFriendlyLinkQuery;
import com.ruoyi.system.domain.news.vo.NewsFriendlyLinkVo;
import com.ruoyi.system.service.news.NewsFriendlyLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsFriendlyLink")
@Api(value = "newsFriendlyLinkApiController", tags  = "友情链接Api")
public class NewsFriendlyLinkApiController extends BaseController {

	@Resource
	private NewsFriendlyLinkService newsFriendlyLinkService;

	@ApiOperation(value = "获取单个友情链接信息", notes = "获取单个友情链接信息")
	@GetMapping("/getById")
	public R<NewsFriendlyLink> getById(@RequestParam(value = "id") Long id) {
		NewsFriendlyLinkQuery newsFriendlyLinkQuery = new NewsFriendlyLinkQuery();
		newsFriendlyLinkQuery.setId(id);
		List<NewsFriendlyLinkVo> newsFriendlyLinkList = newsFriendlyLinkService.getNewsFriendlyLinkList(newsFriendlyLinkQuery);
		if (newsFriendlyLinkList!=null&&newsFriendlyLinkList.size()>0) {
			return R.ok(newsFriendlyLinkList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取友情链接信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsFriendlyLinkVo>> list(@RequestBody NewsFriendlyLinkQuery newsFriendlyLinkQuery) {
        newsFriendlyLinkQuery.setIsEnable("1");
		List<NewsFriendlyLinkVo> newsFriendlyLinkList = newsFriendlyLinkService.getNewsFriendlyLinkList(newsFriendlyLinkQuery);
		return R.ok(new PageInfo<>(newsFriendlyLinkList));
	}
}
